package com.demo.springstarter.demo;

import com.javasea.spring.starter.config2.CacheService;
import com.javasea.spring.starter.properties.DeptProperties;
import com.javasea.spring.starter.properties.TestC;
import com.javasea.spring.starter.service.SaveTheWorldService;
import com.javasea.spring.starter.service.impl.CommonSaveTheWorldServiceImpl;
import com.javasea.spring.starter.service.impl.HeroSaveTheWorldImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 *@ClassName springStarter2Demo
 *@Description TODO
 *@Author longxiaonan@163.com
 *@Date 2022/5/1 0001 18:25
 */
@RestController
@RequestMapping("/demo")
public class springStarter2Demo {

    @Autowired
    private DeptProperties deptProperties;

    @Autowired
    private List<String> books;

    @Autowired
    private TestC testC;

    @GetMapping("/test")
    public void test(){
        System.out.println(deptProperties);
        System.out.println(books);
        testC.printName();
    }

    @Autowired
    private CommonSaveTheWorldServiceImpl commonSaveTheWorldService;
    @Autowired
    private HeroSaveTheWorldImpl heroSaveTheWorld;

    private static final String HERO = "laihaohua";

    // http://localhost:8080/demo/saveTheWorld
    @RequestMapping("/saveTheWorld")
    public String index(String name) {
        SaveTheWorldService saveTheWorldService;
        if(HERO.equals(name)){
            saveTheWorldService = heroSaveTheWorld;
        }else {
            saveTheWorldService = commonSaveTheWorldService;
        }
        return saveTheWorldService.saveTheWorld("aaa");
    }

    @Autowired
    private CacheService cacheService;

    @GetMapping("/cacheService")
    public String cacheService(){
        System.out.println(cacheService);
        return "";
    }
}
